<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form class="layui-form" lay-filter="instr_info" id="instr_info_form" action="" style="padding:15px 10px;">
    <input type="hidden" name="instrId" id="instrId">
    <input type="hidden" name="instrPic" id="instrPic">
    <div class="layui-form-item">
        <label class="layui-form-label">仪器名称：</label>
        <div class="layui-input-block">
            <input type="text" name="instrName" required  lay-verify="required" placeholder="仪器名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">价格：</label>
        <div class="layui-input-block">
            <input type="text" name="jiage" required  lay-verify="required" placeholder="价格" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否可用：</label>
        <div class="layui-input-block">
            <input type="checkbox" value="1" name="instrStatus" lay-filter="switchTest" lay-skin="switch" lay-text="ON|OFF">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">仪器介绍：</label>
        <div class="layui-input-block">
            <textarea id="demo" class="layui-textarea" name="instrText" style="display: none;"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">仪器图片：</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="upload">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <div class="layui-upload-list">
                <img class="layui-upload-img" id="demo1" style="width: 300px;height: 300px">
                <p id="demoText"></p>
            </div>
        </div>
    </div>




    <script>

        setTimeout(function () {
            $("#demo1").attr("src","${path}/"+$("#instrPic").val());
        },500)

        layui.form.render();

        //富文本编辑器组件
        var layedit = layui.layedit;
        layedit.build('demo'); //建立编辑器


        //上传组件
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#upload' //绑定元素
            ,accept: 'file'
            ,url: '${path}/ins/zhiliaoyitupian' //上传接口
            ,done: function(res){
                console.log(res);
                $('#demo1').attr('src',"${path}/"+res.imgPath); //图片链接（base64）
                $("#instrPic").val(res.imgPath);
            }
            ,error: function(){
                //请求异常回调
            },before: function(obj){
                console.log(obj)
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){


                });
            }
        });

    //    监听开关
        layui.form.on('switch(switchTest)', function(data){
            layer.msg('仪器状态：'+ (this.checked ? '可用' : '不可用'), {
                offset: '6px'
            });
        });

    </script>
</form>
</body>
</html>
